#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

const int sonnum=26, base='a';

struct Trie
{
      int num;  
	  bool terminal; 
	  struct Trie *son[sonnum];
      Trie()
      {
          num=1; terminal=false;
          memset(son,NULL,sizeof(son));
      }
};

Trie* NewTrie()
{
    Trie *temp=new Trie();
    return temp;
}

void Insert(Trie *root, char *s)
{
    Trie *temp=root;
    while(*s)
    {
        if(temp->son[*s-base]==NULL)   
			temp->son[*s-base]=NewTrie();
        else 
                temp->son[*s-base]->num++;
        temp=temp->son[*s-base];
        s++;
    }
    temp->terminal=true; 
}

void Search(Trie *root, char *s)
{
    printf("%s ",s);
	Trie *temp=root;
    while(*s)
    {
        if(temp->num > 1)
		{
			printf("%c",s[0]);
            temp=temp->son[*s-base];
		}
		else break;
        s++;
    }
	printf("\n") ;
}
int main()
{
	char inf[10001][25];
	int cnt=1;
	Trie *root=NewTrie();
	root->num=100000;
	while(scanf("%s",inf[cnt])!=EOF)
	{
		Insert(root,inf[cnt]);
		cnt++;
	}
	for(int i=1;i<cnt;i++)
		Search(root,inf[i]);
	return 0;
}





